package com.tg.service.base.factorybean;

import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.context.annotation.ImportBeanDefinitionRegistrar;
import org.springframework.core.type.AnnotationMetadata;

public class ImportMyBean implements ImportBeanDefinitionRegistrar {

    @Override
    public void registerBeanDefinitions(AnnotationMetadata importingClassMetadata, BeanDefinitionRegistry registry) {

        BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition(MyBeanAFactoryBean.class);
        BeanDefinition beanDefinition = builder.getBeanDefinition();
        beanDefinition.setAutowireCandidate(true);
        beanDefinition.setLazyInit(false);

        registry.registerBeanDefinition(MyBeanAFactoryBean.class.getSimpleName(), beanDefinition);

        BeanDefinitionBuilder builder2 = BeanDefinitionBuilder.genericBeanDefinition(MyService.class);
        BeanDefinition beanDefinition2 = builder2.getBeanDefinition();
        beanDefinition2.setAutowireCandidate(true);
        beanDefinition2.setLazyInit(false);

        registry.registerBeanDefinition(MyService.class.getSimpleName(), beanDefinition2);
    }
}
